//
//  NSUDManager.m
//  MyProject
//
//  Created by 石小强 on 2018/3/21.
//  Copyright © 2018年 yanjiaming. All rights reserved.
//

#import "NSUDManager.h"

@implementation NSUDManager

static UserModel *currentUser = nil;

+ (void)setCurrentUser:(UserModel *)user {
    [[NSUserDefaults standardUserDefaults] setValue: (user == nil ? nil : [user keyedArchiverObject]) forKey:@"currentUser"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    currentUser = user;
}

+ (UserModel *)currentUser {
    if(currentUser == nil){
        NSData* currentData = [[NSUserDefaults standardUserDefaults] valueForKey:@"currentUser"];
        currentUser = [UserModel unarchiveObjectWithDate:currentData];
    }
    return currentUser;
}

+ (id)getValueforKey:(NSString*)key {
    return [[NSUserDefaults standardUserDefaults] valueForKey:key];
}

+ (void)synchronize {
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (void)synSetValue:(id)value forKey:(NSString*)key {
    [[NSUserDefaults standardUserDefaults] setValue:value forKey:key];
    [[NSUserDefaults standardUserDefaults] synchronize];
}


@end
